﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Windows.Forms;
using System.IO;

public partial class UserControl_Restore : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void ButtonConfirm_Click(object sender, EventArgs e)
    {
        string filename, filepath; 
        bool Msg;
        Restoring.Visible = true;
        filename = Path.GetFileName(SelectedFile.Text);
        filepath = Path.GetDirectoryName(SelectedFile.Text) + Path.DirectorySeparatorChar;      
        Msg = Utilities.DatabaseRestore(ConfigurationManager.ConnectionStrings["BookShop"].ConnectionString, filepath, filename);
        if (Msg)
        {
            RestoreSuccess.Visible = true;
            Restoring.Visible = false;
            RestoreFailed.Visible = false;
        }
        else
        {
            RestoreFailed.Visible = true;
            RestoreSuccess.Visible = false;
            Restoring.Visible = false;

        }
    }
    protected void  ButtonBrowse_Click(object sender, EventArgs e)
    {
        OpenFileDialog openBackupFile = new OpenFileDialog();

        openBackupFile.InitialDirectory = "c:\\" ;
        openBackupFile.Filter = "bak files (*.bak)|*.bak|All files (*.*)|*.*" ;
        openBackupFile.FilterIndex = 1 ;
        openBackupFile.RestoreDirectory = true ;
        openBackupFile.Multiselect = false;
        openBackupFile.Title = "选择备份文件";

        if (openBackupFile.ShowDialog() == DialogResult.OK)
        {
            SelectedFile.Text = openBackupFile.FileName;

            FileInfo backupFile = new FileInfo(SelectedFile.Text);
            BackupTime.Text = backupFile.CreationTime.ToString();            
        }
        else return;
    }
}
